// pages/Distribution/Distribution.js
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    menu: [
      {
        title: "分销佣金",
        num: 0.0,
        icon: "../../image/menu_1.png"
      },
      /*  {
          title: "分销订单",
          num: 0.0,
          icon: "../../image/menu_2.png"
        },
        {
          title: "提现明细",
          num: 0.0,
          icon: "../../image/menu_3.png"
        },*/
      {
        title: "下线用户",
        num: 0.0,
        icon: "../../image/xianxian.png",
        nav: "navMember"
      },
      {
        title: "推广方案",
        icon: "../../image/menu_5.png",
        nav: "getMyCode"
      },
    ],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getDeviceOptions();//獲取設備高寬
    getDistribution(this);//获取用户佣金信息
    this.setData({
      userInfo: wx.getStorageSync('userInfo')
    })

  },
  getMyCode: function () {
    wx.navigateTo({
      url: '../../pages/myCode/myCode',
    })
  },


  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function (res) {
    return {
      title: '美甲美睫半永久化妆造型',
      path: '/pages/homepage/homepage?id=' + wx.getStorageSync("userid"),
    }
  },
  getDeviceOptions: function () {
    var that = this;
    wx.getSystemInfo({//获取滑块的高宽
      success: function (res) {
        that.setData({
          winWidth: res.windowWidth,
          winHeight: res.windowHeight
        });
      }
    });
  },
  navMember: function () {
    wx.navigateTo({
      url: '../../pages/member/member',
    })
  }
  , getMoney: function () {
    var that = this;
    console.log(wx.getStorageSync("userInfo").nickName);
    wx.request({
      url: app.globalData.allUrl + "/userAction/userDrawings",
      data: {
        merchantId: wx.getStorageSync("userid"),
        typeId: 0,
        withdrawPeople: wx.getStorageSync("userInfo").nickName
      },
      method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
      // header: {}, // 设置请求的 header
      success: function (res) {
        console.log(res);
        if (res.data == "true") {
          wx.showModal({
            title: '提现结果',
            content: '恭喜您提现成功！',
          })
          getDistribution(that)
        } else {
          wx.showModal({
            title: '提现结果',
            content: '提现失败！提现金额少于100无法提现',
          })
        }

      }
    })
  }

  ,
  getMoneys: function () {
    var that = this;
    wx.showModal({
      title: '提现',
      content: '是否立即提现？',
      success: function (res) {
        if (res.confirm) {
          that.getMoney();
        } else if (res.cancel) {
        }
      }
    })
  }
})


function getDistribution(that) {
  wx.request({
    url: app.globalData.allUrl + "/user/pid",
    data: {
      user_id: wx.getStorageSync("userid")
    },
    method: 'POST', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
    // header: {}, // 设置请求的 header
    success: function (res) {
      console.log(res.data)
      that.data.menu[0].num = res.data.all_money;
      that.setData({
        userDistribution: res.data,
        menu: that.data.menu
      })
     // getMembers(that)
    }
  })
}